﻿namespace EyeSoft.Domain.Test.Transactional
{
	using System.Collections.Generic;
	using System.Linq;

	using EyeSoft.Domain.Transactional;
	using EyeSoft.Domain.Transactional.Implementations;
	using EyeSoft.Testing.Domain;

	using Microsoft.VisualStudio.TestTools.UnitTesting;

	using SharpTestsEx;

	[TestClass]
	public class ReadOnlyRepositoryTest
	{
		[TestMethod]
		public void ReadOnlyRepository()
		{
			const string Expected = "Bill";

			var data = new List<IAggregate>
				{
					new Customer { Name = Expected }
				};

			using (var transactionalCollection = new ReadOnlyTransactionalCollection(data))
			{
				using (var uow = new CustomerUnitOfWork(transactionalCollection))
				{
					uow
						.CustomerRepository
						.Single().Name.Should().Be.EqualTo(Expected);
				}
			}
		}

		private class CustomerUnitOfWork
			: ReadOnlyUnitOfWork
		{
			public CustomerUnitOfWork(IReadOnlyTransactionalCollection transactionalCollection)
				: base(transactionalCollection)
			{
			}

			public CustomerRepository CustomerRepository { get; private set; }
		}

		private class CustomerRepository :
			ReadOnlyRepository<Customer>
		{
			public CustomerRepository(IReadOnlyRepository<Customer> session)
				: base(session)
			{
			}
		}

		private class Customer : Aggregate
		{
			public string Name { get; set; }
		}
	}
}